package com.hephesto.infra.security.key;

import java.security.SecureRandom;

import com.hephesto.infra.security.crypto.helper.CryptographerHelper;

/**
 * 
 */
public class RandomSecurityKey {
	
	private static RandomSecurityKey instance;

	private RandomSecurityKey() {}

	public static RandomSecurityKey getInstance() {
		if (instance == null) 
			instance = new RandomSecurityKey();
		return instance;
	}

	public static String generateSecurityKey(Integer digits) {
		byte[] key;
		boolean search = true;
		do {
			key = new SecureRandom().generateSeed(digits / 2);
			for (int i = 0; i < key.length; i++) {
				if ((key[i] % 16) > 10) {
					search = false;
					break;
				}
			}
		} while (search);
		return CryptographerHelper.byteArrayToHexString( key );
	}

}